package cn.itcast.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/sessions")
@Slf4j
public class SessionController {
    @GetMapping( "/s1")
    public void setData(String username, HttpSession session){
        log.warn("session的Id是:{}", session.getId());
        session.setAttribute("username", username);
    }
    @GetMapping( "/s2")
    public void getData(HttpSession session){
        log.warn("session的Id是:{}", session.getId());
        Object username = session.getAttribute("username");
        System.out.println( username);
    }

}
